package com.itdfq.loginuser.service;

import com.itdfq.loginuser.dao.DfqUsersMapper;
import com.itdfq.loginuser.domain.DfqUsers;
import com.itdfq.loginuser.domain.DfqUsersExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: GodChin
 * @Date: 2021/8/19 18:05
 * @Blog: itdfq.com
 * @QQ: 909256107
 * @Description:
 */
@Service
public class UserService {
    @Autowired
    private DfqUsersMapper dfqUsersMapper;

    public List<DfqUsers> findAll() {
        DfqUsersExample dfqUsersExample = new DfqUsersExample();
        dfqUsersExample.createCriteria().andDeleteIdEqualTo(0);
        return dfqUsersMapper.selectByExample(dfqUsersExample);
    }

    public List<DfqUsers> findByUser(DfqUsers dfqUsers) {
        DfqUsersExample dfqUsersExample = new DfqUsersExample();
        DfqUsersExample.Criteria criteria = dfqUsersExample.createCriteria();
        if (dfqUsers.getUsername() != null) {
            criteria.andUsernameEqualTo(dfqUsers.getUsername());
        }
        criteria.andDeleteIdEqualTo(0);
        return dfqUsersMapper.selectByExample(dfqUsersExample);
    }

    public DfqUsers findById(Integer id) {
        return dfqUsersMapper.selectByPrimaryKey(id);
    }

    /**
     * 按照主键选择性更新
     *
     * @param dfqUsers
     */
    public void update(DfqUsers dfqUsers) {
        dfqUsersMapper.updateByPrimaryKeySelective(dfqUsers);
    }


}
